/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package isen.hibernate;

import isen.database.Sensor;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author isen
 */
public class SensorHelper {
    Session session = null;

    public SensorHelper() {
        this.session = HibernateUtil.getSessionFactory().getCurrentSession();
    }
    
    public List getAllSensors() {
    List<Sensor> sensorList = null;
    try {
        org.hibernate.Transaction tx = session.beginTransaction();
        Query q = session.createQuery ("from Sensor");
        sensorList = (List<Sensor>) q.list();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return sensorList;
    }
    
    public Sensor getSensorWithId(int id) {
    List<Sensor> sensors = null;
    try {
        org.hibernate.Transaction tx = session.beginTransaction();
        Query q = session.createQuery ("from Sensor as sensor where sensor.id = "+id +"");
        sensors = (List<Sensor>) q.list();
    } catch (Exception e) {
        e.printStackTrace();
    }
   
    
    return sensors.get(0);
}
}
